home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.07 Jul 95 / 11.07 Tips < prev    next >
Encoding:
Text File  |  1995-06-05  |  4.0 KB  |  103 lines  |  [TEXT/R*ch]

  1.  
  2. Tag Your PowerPC Code 
  3. With a Call To _eieio()
  4.  
  5. When disassembling PowerPC code with CodeWarrior, it isn’t always easy to find the instructions associated with a given set of C statements.  Putting in call like Debugger(); can turn a leaf routine into a trunk.
  6. If you use the CodeWarrior intrinsic __eieio(), this is no April Fools joke, it will add the eieio instruction to the stream.  Wrap your statements in this and moo.  Also, it is fairly benign to accidentally execute.
  7. Chris Sears
  8. sears@netcom.com
  9.  
  10.  
  11. Load Extensions After Boot-Time.
  12. This is a cool hack to load Extensions without restarting the Mac. It is the main part of my Freeware utility LoadADrive 1.1, that can load a CD-ROM Driver after the Mac has been started. (You can mount CDs without restarting your Mac if you haven’t switched on your CD-ROM Drive at boot time. Works with System 7.x and even PowerMacs)
  13. I also use this code to debug Extensions. It is anoying to reboot the mac all the time. With this code as the main part of a small application and a good Debugger (I use Jasik’s The Debugger) you can easily check the loading of the Extension.
  14. I tested this code with some other Extensions and it works fine. Of course, this simple version will definitly not work with most Extensions, but you can improve the code to handle special situations.
  15. Maybe someone, who has more free time than I have, will even develop an Uninstaller for Extension. You have to keep track of all patches, allocated memory, changes in Low Memory and so on. (not easy, I know :-)
  16. I just want to demonstrate that it is NOT impossible to load Extensions after boot time.
  17.  
  18. Dieter Spaar
  19. Friedberg, Germany
  20.  
  21. Boolean LoadInit(FSSpecPtr extensionFSSpec)
  22. {
  23.     short refNum, ret;
  24.     Handle hdl;
  25.  
  26.     // Open resource fork
  27.  
  28.     refNum = FSpOpenResFile(extensionFSSpec, fsCurPerm);
  29.     if(refNum == -1 || ResError() != noErr)
  30.         return FALSE; // Cannot open file
  31.  
  32.     // Load INIT into System Zone
  33.  
  34.     SetZone(SystemZone()); // Set zone to system zone
  35.     hdl = Get1IndResource(‘INIT’,1);
  36.     if(hdl == 0) {
  37.         SetZone(ApplicZone());
  38.     CloseResFile(refNum);
  39.     return FALSE; // Cannot load INIT from driver
  40.     }
  41.  
  42.     HLock(hdl); // lock the resource
  43.     HNoPurge(hdl);
  44.  
  45.     // Call INIT, we don’t handle the return value ret here
  46.  
  47.     ret = (*(short(*)())(*hdl))(); // Looks nice, doesn’t it ;-)
  48.  
  49.      // Is it still a resource ? (don’t unlock if detached)
  50.      // Some INIT’s detach the resource to keep the INIT’s memory block
  51.  
  52.     if(HGetState(hdl) & 0x20)
  53.     {
  54.         HUnlock(hdl);
  55.         ReleaseResource(hdl);
  56.     }
  57.  
  58.     SetZone(ApplicZone()); // Back to application zone
  59.     CloseResFile(refNum); // Close the resource file
  60.  
  61.     // Redraw desktop (Extension may draw startup icon)
  62.  
  63.     PaintOne(nil, GetGrayRgn());
  64.  
  65.     return TRUE;
  66. }
  67.  
  68.  
  69.  
  70.  
  71. ...And Thus Spake the App, “Another Bug!”
  72. Have a piece of code that hard to debug with the debugger?  Trying to debug a code resource?  Usually a quick and dirty solution is to put in a bunch of SysBeep(10) calls to get an idea of where your code is at.  However, you can use Apple’s Speech Manager in a similar fashion and get a much better “speak-out”.  Here’s how:
  73. Include SpeakIt.c to your project.  (The code is included on the disk, and at the usual online places.) Include SpeakIt.h in all the files you want to have any debug statements spoken.  In SpeakIt.h is the macro DebugSpeech.  Define it like “#define DebugSpeech       1” when you want to use the speech debugger, and comment it out when you don’t want to use it. Within the code you want to debug, call the speech debugger by adding code like this example:
  74.  
  75. #ifdef DebugSpeech
  76.     CheckSpeechMgr();   // should be called once in your initialization code
  77. #endif
  78.  
  79. . code ...
  80.  
  81. #ifdef DebugSpeech
  82.     SpeakIt( “Before while loop.”, true );
  83. #endif
  84.  
  85. . more code ...
  86.  
  87. #ifdef DebugSpeech
  88.     SpeakIt( “Made it through the while loop.”, true );
  89. #endif
  90.  
  91. . and more code ...
  92.  
  93. #ifdef DebugSpeech
  94.     SpeakIt( “Right before bringing up main window.”, true );
  95. #endif
  96.  
  97.  
  98. Cool!
  99.  
  100. Bill Modesitt
  101. billm@maui.com, http://www.maui.com/~billm
  102. T
  103.